﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neudesic.Pulse.Entities;
using System;

namespace Neudesic.Pulse.Client.Tests
{
    /// <summary>
    /// Summary description for RestResourceClientDeleteTests
    /// </summary>
    [TestClass]
    public class RestResourceClientDeleteTests
    {

        private TestContext testContextInstance;
        PulseClient client = new PulseClient(TestHelper.BaseAddress, AuthenticationScheme.Ntlm);

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        [TestCategory("Integration")]
        public void RestResourceClient_DeleteActivity()
        {

            // First post a new activity so we can delete it later.
            Entity me = client.CurrentUser;
            StatusRequest entity = new StatusRequest()
            {
                Text = string.Format("Sample unit test message.  {0}", Guid.NewGuid().ToString())
            };

            string location = client.Post(entity, me.Feed.Url); // Post to my activities

            // Grab the status
            Activity message = client.Get<Activity>(location, "activity");

            Assert.IsNotNull(message);
            Assert.IsFalse(string.IsNullOrEmpty(message.Text));

            // Now delete the status
            client.Delete(location);

            try
            {
                // Re-get the message to make sure it's gone.
                message = client.Get<Activity>(location);

                Assert.Fail("Did not get an exception as expected.");

            }
            catch (RestClientException ex)
            {
                Assert.AreEqual<int>(404, ex.StatusCode);
            }

        }
    }
}
